var e = require;
var t = module;
var o;
(o = e("DirCtl")) && o.__esModule,
    cc.Class({
        extends: cc.Component,
        properties: {
            prefabWin: cc.Prefab,
            prefabFail: cc.Prefab,
            prefabDirCtl: cc.Prefab,
            labelLvScore: cc.Label,
            labelLvNum: cc.Label,
            pbScoreIcon: cc.Prefab,
            pbPopSth: cc.Prefab
        },
        onDestroy: function onDestroy() {
            this.failTimeout && clearTimeout(this.failTimeout),
                this.popSthInterval && clearInterval(this.popSthInterval),
                "TT" == lplatform.channel && lplatform.hideBanner(),
                lplatform.stopRecord();
        },
        onLoad: function onLoad() {
            (window.ui = this), (this.showedScore = -1);
        },
        start: function start() {
            var e = this;
            (this.labelLvNum.string = "关卡" + (lGlobal.realLevel + 1)),
                (this.popSth = null),
                (this.popSthInterval = setInterval(function () {
                    if (!e.popSth) {
                        var t = cc.instantiate(e.pbPopSth);
                        (t.parent = e.node), (e.popSth = t);
                    }
                }, 4e4)),
                (this.showedScore = lGlobal.userData.score),
                (this.labelLvScore.string = "" + this.showedScore),
                cc.audioEngine.setMusicVolume(0.1),
                lplatform.startRecord(),
                "TT" != lplatform.channel && lplatform.showBanner();
        },
        dirCb: function dirCb(e, t, o, n) {
            window.game.slug.updateDir(e, t, o, n);
        },
        onClickFailJumpLv: function onClickFailJumpLv() {},
        onClickFailHome: function onClickFailHome() {
            cc.director.loadScene("Menu"), soundMgr.playSound(soundMgr.btn);
        },
        onClickGameRetry: function onClickGameRetry() {
            soundMgr.playSound(soundMgr.btn), lGlobal.loadLevel(void 0, lGlobal.realLevel);
        },
        onClickGameJump: function onClickGameJump() {
            var e = this;
            lplatform.showRewardedVideo(function (t) {
                t && e.win();
            }),
                soundMgr.playSound(soundMgr.btn);
        },
        win: function win() {
            (this.nodeWin = cc.instantiate(this.prefabWin)),
                (this.nodeWin.parent = this.node),
                (this.nodeWin.active = !0),
                (lGlobal.userData.levelState[lGlobal.model][lGlobal.realLevel] = 2),
                (lGlobal.userData.levelState[lGlobal.model][lGlobal.realLevel + 1] = 3),
                lGlobal.userData.modelLevel[lGlobal.model] < lGlobal.realLevel + 1 &&
                    (lGlobal.userData.modelLevel[lGlobal.model] = lGlobal.realLevel + 1),
                lGlobal.saveUserData(),
                soundMgr.playSound(soundMgr.win);
        },
        fail: function fail() {
            var e = this;
            this.failTimeout = setTimeout(function () {
                (e.nodeFail = cc.instantiate(e.prefabFail)),
                    (e.nodeFail.parent = e.node),
                    (e.nodeFail.active = !0),
                    soundMgr.playSound(soundMgr.lose);
            }, 2e3);
        },
        onClickBackToMain: function onClickBackToMain() {
            cc.director.loadScene("Menu"), soundMgr.playSound(soundMgr.btn);
        },
        addScore: function addScore(e, t) {
            (lGlobal.userData.score += e), this.addScoreAni(e, t);
        },
        addScoreAni: function addScoreAni(e, t) {
            if (t) {
                var o = t.convertToWorldSpaceAR(cc.Vec2.ZERO),
                    n = packMan.mcamera.getWorldToScreenPoint(o),
                    i = this.node.convertToNodeSpaceAR(n),
                    a = this.node.convertToNodeSpaceAR(this.labelLvScore.node.convertToWorldSpaceAR(cc.Vec2.ZERO)),
                    r = cc.instantiate(this.pbScoreIcon);
                (r.parent = this.node),
                    (r.position = i),
                    cc
                        .tween(r)
                        .to(1, {position: a}, {easing: "sineOutIn"})
                        .call(function () {
                            r.destroy();
                        })
                        .start();
            }
        },
        update: function update() {
            if (this.showedScore != lGlobal.userData.score) {
                var e = lGlobal.userData.score - this.showedScore;
                (e /= Math.abs(e)), (this.showedScore += e), (this.labelLvScore.string = "" + this.showedScore);
            }
        }
    });
